package com.fowo.api.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.fowo.api.common.mybatis.interceptor.RolePermissionInterceptor;
import com.fowo.api.common.mybatis.interceptor.SqlHelperInterceptor;

import com.fowo.api.sys.rd2.interceptor.RoleData2Interceptor;
import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

import java.util.Properties;

/**
 * Mybatis Plus 配置
 * @author yl_ls
 */
@Configuration
public class MybatisPlusConfig {

    @Bean
    @Order(1)
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//        interceptor.addInnerInterceptor(new RolePermissionInterceptor());
        interceptor.addInnerInterceptor(new RoleData2Interceptor());
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return interceptor;
    }

    @Bean
    @Order(2)
    public SqlHelperInterceptor sqlHelperInterceptor() {
        return new SqlHelperInterceptor();
    }

    @Bean
    public DatabaseIdProvider databaseIdProvider() {
        VendorDatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
        Properties properties = new Properties();
        properties.put("MySQL", "mysql");
        properties.put("SQL Server", "sqlserver");
        databaseIdProvider.setProperties(properties);
        return databaseIdProvider;
    }
}
